﻿#coding=utf-8
from django.db import connection


def GetEvent():
	cur=connection.cursor()
	cur.execute("set names utf8")
	sql="select id,startdate,enddate,text from scheduler_scheduler"
	cur.execute(sql)
	result=cur.fetchall()
	cur.close()
	returninfo="<data>"
	for id,startdate,enddate,text in result:
		returninfo=returninfo+"<event id='%s' start_date='%s' end_date='%s' text='%s'/>"%(id,startdate,enddate,text)
	returninfo=returninfo+"</data>"
	#f.write(returninfo)
	#f.close()
	return returninfo
	
def ModifyEvent(result):
	sql="replace into scheduler_scheduler(id,startdate,enddate,text,writedate) values(%s,'%s','%s','%s',now())"%(result['id'],result['start_date'],result['end_date'],result['text'])
	cur=connection.cursor()
	cur.execute(sql)
	cur.execute("commit")
	cur.close()
	
def DelEvent(eventid):
	sql="delete from scheduler_scheduler where id=%s"%eventid
	cur=connection.cursor()
	cur.execute(sql)
	cur.execute("commit")
	cur.close()